/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AdministradorReporteInventario.java
 *
 * Created on 19-nov-2009, 22:35:12
 */

package scapi.gui;

import java.rmi.RemoteException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
import scapi.entidades.CatalogoProducto;
import scapi.servidor.servidores.ServidorACatalogoProd;
import scapi.servidor.servidores.ServidorReporte;
import scapi.utilerias.ExcepcionValidacion;
import scapi.utilerias.ServidorFactory;

/**
 *
 * @author Emmanuel
 */
public class AdministradorReporteInventario extends javax.swing.JPanel {
    private ServidorACatalogoProd servACProducto;
    private ServidorReporte reportes;

    /** Creates new form AdministradorReporteInventario */
    public AdministradorReporteInventario() {
        initComponents();
        try{
            servACProducto =  (ServidorACatalogoProd) ServidorFactory.obtenerServidor(ServidorFactory.ServidorCatalogoProducto);
            CatalogoProducto[] catalogo = servACProducto.consultaCatalogoProducto();
            cmbCategoria.setModel(new DefaultComboBoxModel(catalogo));
            reportes = (ServidorReporte) ServidorFactory.obtenerServidor(ServidorFactory.ServidorReportes);


        }catch(Exception e){
            e.printStackTrace();
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel4 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        cmbCategoria = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        cmbPresentacion = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        cmbEstado = new javax.swing.JComboBox();

        jLabel4.setText("jLabel4");

        jButton2.setText("Aceptar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24));
        jLabel1.setText("Reporte Inventario");

        jLabel3.setText("Catalogo");

        cmbCategoria.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Todas", "Prendas", "Joyeria" }));

        jLabel5.setText("Presentacion");

        cmbPresentacion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Muy buena", "Buena", "Regular", "Mala", "Muy mala" }));

        jLabel6.setText("Estado");

        cmbEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Activo", "En venta", "Vencido", "Vendido" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addContainerGap(287, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel3))
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cmbCategoria, 0, 377, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(cmbPresentacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel6)
                                        .addGap(25, 25, 25)
                                        .addComponent(cmbEstado, 0, 189, Short.MAX_VALUE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGap(31, 31, 31))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(cmbCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmbPresentacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(cmbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jButton2)
                .addContainerGap(13, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed


        try {
             if(cmbCategoria.getSelectedIndex() == 0)
            throw new ExcepcionValidacion("Debe elejir una categoria");

        CatalogoProducto id = (CatalogoProducto) cmbCategoria.getSelectedItem();
        String id_catalogo = id.getNomCProducto();
        String presentacion = (String) cmbPresentacion.getSelectedItem();
        String status = (String) cmbEstado.getSelectedItem();




        HashMap<String,String> hm = new HashMap<String, String>();
        hm.put("id_catalogo", id_catalogo);
        hm.put("presentacion", presentacion);
        hm.put("status", status);
            JasperPrint print = reportes.getReporte("Inventario.jasper", hm);
            JasperViewer.viewReport(print,false);
            // TODO add your handling code here:
        } catch (RemoteException ex) {
            Logger.getLogger(AdministradorReporteInventario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(AdministradorReporteInventario.class.getName()).log(Level.SEVERE, null, ex);
        } catch (JRException ex) {
            Logger.getLogger(AdministradorReporteInventario.class.getName()).log(Level.SEVERE, null, ex);
        }catch(ExcepcionValidacion e){
            JOptionPane.showMessageDialog(this, e.getMessage(),"ERROR", JOptionPane.ERROR_MESSAGE);
        }



        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cmbCategoria;
    private javax.swing.JComboBox cmbEstado;
    private javax.swing.JComboBox cmbPresentacion;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    // End of variables declaration//GEN-END:variables

}
